package com.cskaoyan.controller;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.domain.MarketUser;
import com.cskaoyan.service.FootprintService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/wx/footprint")
public class WxFootprintController {
    @Autowired
    FootprintService footprintService;
    @GetMapping("list")
    public BaseRespVo list(Integer page, Integer limit) {
        Subject subject = SecurityUtils.getSubject();
        Integer userId=0;
        if (subject.isAuthenticated()) {
            MarketUser principal = (MarketUser) subject.getPrincipal();
            userId = principal.getId();
        }
      BaseRespVo baseRespVo=footprintService.getList(page,limit,userId);
        return baseRespVo;
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody Map map) {
        Subject subject = SecurityUtils.getSubject();
        Integer userId=0;
        if (subject.isAuthenticated()) {
            MarketUser principal = (MarketUser) subject.getPrincipal();
            userId = principal.getId();
        }
        Integer id = (Integer) map.get("id");
        BaseRespVo baseRespVo=footprintService.deleteFootprint(id,userId);
        return baseRespVo;
    }
}
